if (!jsx3.lang.Class.forName("ux.cdb.admin.loan.loanWizard.CoDebitContent")) {
/**
 * Define the <code>name of class</code> class.
 * This class inherit from <code>jsx3.gui.Block<code> GUI class.
 */
jsx3.Class.defineClass(
    "ux.cdb.admin.loan.loanWizard.CoDebitContent",
    jsx3.gui.Block,
    null,
    function (coDebitContent) {
      /**
       * This method will be called after UI file has deserialized.
       */
      
      coDebitContent.prototype.homedir = 'ux/cdb/admin/loan/';
      
      coDebitContent.prototype.bind = function(fn, scope) {
        scope = scope || this;
        return function() {
          fn.apply(scope, arguments)
        }
      };
      
      coDebitContent.prototype.onAfterDeserialize = function() {
      	this.initlized = false;
      	
      }
      
      coDebitContent.prototype.onAfterPaint = function(){
      	jsx3.log('step2 onAfterPaint begin-------------------');
      	jsx3.log('step2 this.initlized:'+this.initlized);
      	if(this.initlized){
      		return;
      	}
      	this.initlized = true;
      	try{
        var me = this;
        this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
        this.dialog = this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder");
        this.block_loan_step2_gd = this.get("block_loan_step2_gd");
        jsx3.log('step2 onAfterPaint studentName:'+this.dialog.studentName);
        jsx3.log('step2 onAfterPaint studentCertId:'+this.dialog.studentCertId);
        this.get("blkField_studentName").getChild(1).setText(this.dialog.studentName,true);
				this.get("blkField_studtCertId").getChild(1).setText(this.dialog.studentCertId,true);
				this.get("blkField_certType").getChild(1).setValue("01");	
        	//if(!this.initlized){
        		jsx3.log('step2 onAfterPaint call loadCache');
        		ux.cdb.admin.CommonCache.loadCache(['CERT_TYPE','HEALTH_STATUS','RELATED_GUARANTEE_TYPE','APP_TYPE','APP_REASON'], me, me.onSelectListLoaded);
      		//	this.initlized = true;
      		//}else{
      		//	this.onSelectListLoaded();
      		//}
        }catch(e){
						jsx3.log('step2 onAfterPaint: ' + e.message);
				}  
        jsx3.log('step2 onAfterPaint end------------------');		      
      }
      
      coDebitContent.prototype.onSelectListLoaded = function() {
      	jsx3.log('onSelectListLoaded begin------------------');		  
      	var me = this;
      	try{
      		var cache = ux.cdb.admin.CommonCache.getInstance();
      		this.get('blkField_certType').getChild(1).setSourceXML(cache.getCache('CommonCache_CERT_TYPE'));
      		this.get('blkField_certType').getChild(1).repaint();
      		this.get('blkField_health').getChild(1).setSourceXML(cache.getCache('CommonCache_HEALTH_STATUS'));
      		this.get('blkField_health').getChild(1).repaint();
			this.get('blkRelationOfStudent').getChild(1).setSourceXML(cache.getCache('CommonCache_RELATED_GUARANTEE_TYPE'));
      		this.get('blkRelationOfStudent').getChild(1).repaint();
			//this.get('blkEarningOfYea').getChild(1).setSourceXML(cache.getCache('CommonCache_ANNUAL_INCOME'));
      		this.dialog.get("wizPane_3").onSelectListLoaded();
      	}catch(e){
						jsx3.log('onSelectListLoaded callback Error : ' + e.message);
				}
     
				if(this.dialog.Operation && this.dialog.Operation == "Edit"){  
					jsx3.log('step2  this.dialog.Operation edit: ' + this.dialog.Operation);      	
        	this.setControlsState('blkInput2', true);
       		this.setControlsState('blkInput3', true);
        	this.setControlsState('blkInput4', true);
          this.SetNextButton(true);
        	setTimeout(function() {me.loadInfo();}, 0);
        }		
				
				if(!(this.dialog.Operation && this.dialog.Operation == "Edit")){
					var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@MainPage@PleaseSelect");
      		this.get("blkField_certType").getChild(1).setValue("01");    
      		//this.get("blkField_health").getChild(1).setValue(tip);    
      		//this.get("blkRelationOfStudent").getChild(1).setValue(tip);    
      		//this.get("blkEarningOfYea").getChild(1).setValue(tip);    
      		     		
      		//this.get("blkInProvince").repaint(); 
      		//this.get("blkField_hujiPlace")repaint();
      	}
      }
      
      coDebitContent.prototype.loadInfo = function() {
      	jsx3.log('loadInfo begin------------------');
      	var params = [];
      	params.push(this.dialog.applyId);
      	var me = this;
      	ux.megatron.util.Dwr.callDwr("AcceptRetailStudentLoanAppUCC", "getRelatedGauranteeInfo", params, me, me.onGetRelatedGauranteeInfoCallback, "AcceptRetailStudentLoanAppUCC");
      }
      
      coDebitContent.prototype.loadInfoStep3 = function() {      	
      	var params = [];
      	params.push(this.dialog.applyId);
      	var me = this;      	
      }
      
      coDebitContent.prototype.onGetRelatedGauranteeInfoCallback = function(reData) {
      	jsx3.log("onGetRelatedGauranteeInfoCallback*********************");
      	if(!reData)
					jsx3.log("call GetRelatedGauranteeInfo failed......");
				
				var flag = reData.res.flag;

        if(flag != 1){
        	var msg = reData.res.msg;
        	alert(msg);
        	jsx3.log("call GetRelatedGauranteeInfo failed: "+msg);
        	return;
        }
      	console.log('onGetRelatedGauranteeInfoCallback data : \n', reData);
      	var realData = reData.content.data[0];
				this.dialog.loan_step2_data = realData; //cache data
      	jsx3.log('party name:'+realData.partyName);
      	jsx3.log('country code1:'+realData.countyCode1);
      	jsx3.log('country code2:'+realData.countyCode2);
      	try{
      		this.block_loan_step2_gd.setDataByObject(realData);
      		//jsx3.log(this.block_loan_step2_gd.getData().toString());
      	}catch(e){
      		jsx3.log("call GetRelatedGauranteeInfo failed: "+ e.message);
      	}
      	this.dialog.get("wizPane_3").loadInfo();
      }
      
      coDebitContent.prototype.loadCertType = function() {
      	ux.megatron.Main.loadResource(this.homedir + "xml/CertType.xml", "ux.cdb.admin", "certType_step2", "xml");
        this.get('blkField_certType').getChild(1).repaint();
        this.get('blkField_certType').getChild(1).setValue("01");
      }
      
      coDebitContent.prototype.onCommonTypeCallback = function(data) {
        //alert(data);
      }
      
      coDebitContent.prototype.getChildOfType = function(parentBlock, isSelect) {
        var type = (isSelect==true)?'jsx3.gui.Select':'jsx3.gui.TextBox';
        return this.get(parentBlock).getDescendantsOfType(type);
      }
      
      coDebitContent.prototype.setControlState = function(control, isEnable) {
        var enable = isEnable?jsx3.gui.Form.STATEENABLED:jsx3.gui.Form.STATEDISABLED;
        if(control) {
          control.setEnabled(enable, true);
        }
      }
      
      coDebitContent.prototype.setControlsState = function(Parent, isEnable) {
        var enable = isEnable?jsx3.gui.Form.STATEENABLED:jsx3.gui.Form.STATEDISABLED;
        var cons = this.get(Parent).getDescendantsOfType('jsx3.gui.Select');
        for (i=0;i<cons.length;i++) {
          cons[i].setEnabled(enable, true);
        }
        var cons = this.get(Parent).getDescendantsOfType('jsx3.gui.TextBox');
        for (i=0;i<cons.length;i++) {
          cons[i].setEnabled(enable, true);
        }
      }
      
      coDebitContent.prototype.onSearch = function() {
		(function(){})();//reset field consumers
        var certId = this.get("blkField_certId").getChild(1).getValue();
		this.block_loan_step2_gd.setDataByObject({
			partyName:null,
			certTypeCode:'01',
			certId:certId,
			healthStatusCode:'',
			relatedGuaranteeTypeCode:'',
			streetAddr:null,
			postalCode:null,
			phoneNbr:null,
			mobileNbr:null,
			employerName1:null,
			dutyName1:null,
			familyIncome:null
		});
		/* this.get("blkField_certType").getChild(1).setValue("01");	
		this.get("blkField_certType").getChild(1).repaint(); */
		
      	this.setControlsState('blkInput2', true);
        this.setControlsState('blkInput3', true);
        this.setControlsState('blkInput4', true);
        this.SetNextButton(true);
        try{
        	var provCode = ux.cdb.admin.Privilege.getProvinceCode();
      		jsx3.log('**********provCode:'+provCode);
      		//var dataCode = {countyCode2:provCode,countyCode1:provCode};
      		this.get("blkInProvince").getChild(1).setValue(provCode);
      		this.get("blkInProvince").onSelectChanged();
      		this.get("blkField_hujiPlace").getChild(1).setValue(provCode);
      		this.get("blkField_hujiPlace").onSelectChanged();
      	}catch(e){
      		jsx3.log("provCode failed: "+ e.message);
      	}
        
        var me = this;
        var certType = this.get("blkField_certType").getChild(1).getValue();
        certId = this.emptyToNull(certId);
        var lbl = this.wizard.getMessageLabel();
		var tip = null;
        if(certId == null){        	
        	tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp2_certId");
        }else if(this.dialog.studentCertId == certId){
			tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp2_certIdAgainst");
		}
		if(tip != null){
			lbl.setText(tip,true);
			this.get("blkField_certId").get('txtValue').focus();
			//this.get('blkField_certType').applyData({certTypeCode:'01'});
			return;
		}

        var params = [];
        params.push(certType);
        params.push(certId);
        jsx3.log('certType:' + certType);
        jsx3.log('certId:' + certId);
        ux.megatron.util.Dwr.callDwr("AcceptRetailStudentLoanAppUCC", 
            "getRelatedGauranteeInfoByCertType", params, me, 
                me.onSearchCallback, "AcceptRetailStudentLoanAppUCC");        
      }
      
      coDebitContent.prototype.emptyToNull = function(sValue) {
      	var result = null;
      	if(sValue != null && sValue.trim().length > 0){
      		result = sValue;
      	}
      	return result;
      }
      
      coDebitContent.prototype.onSearchCallback = function(reData) {       
        if(!reData)
						jsx3.log("call onSearchCallback failed......");
				
				var flag = reData.res.flag;
				jsx3.log("loan step2 flag="+flag);
        if(flag != 1){
        	if(flag == 2){
        		return;
        	}else{
        		var msg = reData.res.msg;
        		//alert(msg);
        		jsx3.log("call load student failed: "+msg);
        		return;
        	}
        }
      	
      	var realData = reData.content.data[0];
		this.getAncestorOfType("ux.megatron.gui.SteppedWizard").block_loan_step2_gd_partyId = realData.partyId;
		this.getAncestorOfType("ux.megatron.gui.SteppedWizard").block_loan_step2_gd_addressId1 = realData.addressId1;
		this.getAncestorOfType("ux.megatron.gui.SteppedWizard").block_loan_step2_gd_addressId2 = realData.addressId2;
		//console.log('onSearchCert data : \n', realData);
		this.dialog.loan_step2_data = realData; //globle cache.
        this.block_loan_step2_gd.setDataByObject(realData);
      }
      
      coDebitContent.prototype.SetNextButton = function(isEnable) {
        var enable = isEnable?jsx3.gui.Form.STATEENABLED:jsx3.gui.Form.STATEDISABLED;
        var wizard = this.getAncestorOfType('ux.cdb.admin.loan.loanWizard.LoanBuilder');
        wizard.get('buttonNext').setEnabled(enable, true);
      }
      
      coDebitContent.prototype.init = function() {
        //this.SetNextButton(false);
      }
      
      coDebitContent.prototype._onMatrixSelect = function(selfobj) {
        this.loadDetails();
      }
      
      
      coDebitContent.prototype.loadMatrixData = function() {
        ux.megatron.Main.loadResource(this.homedir + "xml/CoDebit.xml", "ux.cdb.admin", "studen_0611", "xml");
        this.matrix.repaint();
        this.init();
      }
      
      coDebitContent.prototype.loadDetails = function(){
        var me = this;
        var tabSelectCoDebit = this.get('tabSelectCoDebit').getContentPane();
        if (!tabSelectCoDebit.getFirstChild()) {
          ux.megatron.Main.loadUIResourceAsync(tabSelectCoDebit, "ux.cdb.admin", "ux/cdb/admin/loan/loanWizard/step2/ui/CoDebitSelectTabPan.xml", me, me.onMatrixTabLoaded);
        }
        var tabAddCoDebit = this.get('tabAddCoDebit').getContentPane();
        if (!tabAddCoDebit.getFirstChild()) {
          ux.megatron.Main.loadUIResourceAsync(tabAddCoDebit, "ux.cdb.admin", "ux/cdb/admin/loan/loanWizard/step2/ui/NewCoDebitTabPan.xml", me, me.onEditTabLoaded);
        }
      }
      
      coDebitContent.prototype.onMatrixTabLoaded = function() {
        this.matrix = this.get("tabSelectCoDebit").getContentPane().get("mtxMain");
        var me = this;
        this.loadMatrixData();
        this.get("btnRefresh").OnRefresh = this.bind(me.loadMatrixData, me);
      }

      coDebitContent.prototype.onEditTabLoaded = function() {
        
      }
    }
  );
}